<?php
/* 
 * Department Model
 */

require_once BaseUtil::getModulePath("base")  .  '/models/BaseDao.php';

class DepartmentDao extends BaseDao{

    protected $_name;
    
    public function  _setup() {
        $this->_name = $this->prefix() . "departments";
        parent::_setup();
    }

    public function getDepartmentById($id){
        $select = $this->db_r->select();
        $select->from($this->_name,"*");
        $select->where('id = ?', $id);
        $sql = $select->__toString();
        $result = $this->db_r->fetchRow($sql);
        return $result;
    }

    public function updateDepartment($id,$department){
			$where = $this->db_w->quoteInto('id = ?', $id);
			$this->update($department,$where);
    }

    public function deleteDepartment($id){
            $department = array("is_delete" => 1,'modified'=> date("Y-m-d H:i:s"));
            $where = $this->db_w->quoteInto('id = ?', $id);
            $this->update($department,$where);
    }

    public function getDepartments(){
        $select = $this->db_r->select();
        $select->from($this->_name,"*");
        $select->where("is_delete = 0");
        $sql = $select->__toString();
        $result = $this->db_r->fetchAll($sql);
        return $result;
    }
    
}
